package com.xiaoshuidi.cloud.module.rooms.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoshuidi.cloud.module.rooms.enums.RepairStatusEnum;
import com.xiaoshuidi.cloud.module.rooms.mapper.RoomEquipmentRepairMapper;
import com.xiaoshuidi.cloud.module.rooms.pojo.RoomEquipmentRepair;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@RequiredArgsConstructor
public class RoomEquipmentRepairRepository extends ServiceImpl<RoomEquipmentRepairMapper, RoomEquipmentRepair> {

    private final RoomEquipmentRepairMapper mapper;

    public List<RoomEquipmentRepair> listByEquipmentId(Long equipmentId) {
        LambdaQueryWrapper<RoomEquipmentRepair> wrapper = new LambdaQueryWrapper<RoomEquipmentRepair>()
                .eq(RoomEquipmentRepair::getEquipmentId, equipmentId);
        return mapper.selectList(wrapper);
    }

    public Boolean updateStateById(Long id) {
        RoomEquipmentRepair roomEquipmentRepair = new RoomEquipmentRepair();
        roomEquipmentRepair.setId(id);
        roomEquipmentRepair.setStatus(RepairStatusEnum.FINISHED.getCode());
        mapper.updateById(roomEquipmentRepair);
        return true;
    }

}
